The Absolute Beginners Guide To Amos ------------------------------------- Chapter Seven ------------- Before we start, here are the answers to the quiz in chapter six. 1. B 2. A 3. C 4. A 5. B 6. A 7. A 8. B 9. A 10. A If you got less than five correct then please re-read the corresponding chapters. If you got five to eight correct you are doing great if you got nine or more congratulations and keep it up. --------------------------------------------------------------------------- Now I think it`s time to learn some new commands I have picked out some commands that are fairly straight forward and some others that are a bit more complex, but they are commands that you are going to need to know about. You shouldn`t have too much trouble with this lot. Keep making those notes and refer to them as much as needed. I have been using Stos/Amos for quite a few years now and I still refer to my note book, especially for things like the Amos file selector syntax. I can never remember how that goes. Anyway enough yapping let`s learn something new. BOOM ---- This is fun, BOOM is one of three sound effects already built into Amos for us. It doesn`t need any variables and is a stand alone command. You just simply put BOOM anywhere in your program that you want a BOOM sound, such as an explosion for example. Admittedly BOOM doesn`t sound that great but it is simple and memory efficient. BELL ---- The same as BOOM except giving a simple single bell sound. SHOOT ----- Again the same as above but can be used as a gun firing sound effect. EXAMPLE7.Amos will give you an idea of how to use these effects. WAIT N ------- This command is almost identical to WAIT KEY but more flexible. T he N stands for a number, any number, for example, WAIT 50, would halt the program in it`s tracks for one second and then continue executing from the next command or line. WAIT has nothing to do with key presses or the user so put that out of your mind now. WAIT just WAITs around for N 50ths of a second. Some examples: WAIT 1 REM Wait for 1/50th of a second WAIT 25 REM Wait for half a second WAIT 50 REM wait for one second WAIT 100 REM Wait for two seconds WAIT 500 REM Wait for ten seconds. And so on and so forth. RND (N) ------- RND is short for RANDOM this smart little fellow generates RaNDom numbers for us in any range we want. I will explain by example: RND (5) REM Will produce a random number from 0 to 4 (but not 5) RND (5)+1 REM Will give a random number from 1 to 5, it is the same as above but 1 is added to the result (+1) RND (100) REM Generates a random number from 0 to 99, if we wanted it to include 100 in it`s calculations we just add a +1 RND (100)+1 REM Like this. That`s all very well but to use a RaNDom number we will need to assign it to a variable so we can manipulate it. Luckily, that is quite easy: A=RND(5) REM A equals a random number 0 to 4 A=RND (5)+1 REM A equals a random number 1 to 5 A=RND (100) REM A equals a random number 0 to 99 A=RND(100)+1 REM A equals a random number 1 to 100 A, of course, can be any variable name you wish like GUESS or RN etc. So, we have a variable containing a random number, we know the range of the number but we will have to interrogate the variable to find out the generated random number because it won`t tell us unless we ask: IF A=1 then BOOM REM IF the variable A is equal to one then play the BOOM sound effect. Well that is one way of finding out if the random number is equal to one, but that approach is pretty limited. Let`s suppose we have a simple guessing game where the computer generates a RaNDom number from 0 to 99, the user then INPUTS his guess and the computer responds with a TOO LOW, TOO HIGH or CORRECT message. How do we get Amos to check for higher, lower and equal to the RaNDom number? IF GUESS=RN then bell REM GUESS is the users INPUT, RN the computers RaNDom number, if equal sound the BELL effect. It`s the equals sign that does it. How about higher or lower? IF GUESS>RN THEN BOOM REM If GUESS is more than the RaNDom number THEN sound the BOOM effect. IF GUESS RN THEN LOCATE 0,20: PRINT "TOO HIGH": SHOOT: WAIT 100: GOTO L2 IF GUESS. These signs simply mean. > More than < Less than Examples: IF Jim's age is > Mary's age THEN Jim is older | | MORE THAN IF 12 < 14 THEN BELL | | LESS THAN You can use them both together as well, like this: IF 12 <> 14 THEN BELL | | MORE THAN OR LESS THAN (In other words if 12 doesn't = 14) You can even use the equality sign as well: IF 12 >= 14 THEN BELL | | MORE THAN OR EQUAL TO But you can't use all three like this: IF 12 <=> 14 THEN BELL * SYNTAX ERROR * You may have noticed that the number guessing program has no quit option or an end. I have done this purposefully for two reasons. 1. To keep it as simple as possible and 2. To remind you that to break into an Amos program you simply hold down the Ctrl key and press C on your keyboard. The only time this will not work is if you have implement the BREAK command in your program. BREAK will be covered in a later chapter. Another feature sorely lacking in our number guessing game is the ability to keep track of how many attempts it took for the player to guess the number. Why don't you have a go. A few hints to help you do this. You will need to store the amount of attempts in a variable, you could call it ATTEMPTS for simplicity. Don't forget to set ATTEMPTS to zero when the player starts another game. You will also need to PRINT ATTEMPTS somewhere. So that wraps up this chapter. I hope you remembered to take notes on this lot as we have exams coming up for you very soon! Now is a good time to load up EXAMPLE7.Amos. End of chapter seven ^^^^^^^^^^^^^^^^^^^^